package com.dreem.principle.demeter.improve;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: DesignParrtern
 * @description: Demeter类的改进：根据迪米特法则
 * @author: Peng
 * @create: 2021-01-18  22:00
 **/
public class DemeterUP {
    public static void main(String[] args){
        new SchoolManagerUP().printAllEmployee(new CollegeManagerUP());
    }
}

// 员工类
abstract class EmployeeUP{
    private String id;
    public abstract String getId();
    public abstract void setId(String id);
}

// 学院员工类
class CollegeEmployeeUP extends EmployeeUP {
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

// 学校员工类
class SchoolEmployeeUP extends EmployeeUP {
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

// 学院管理类
class CollegeManagerUP{
    public List<CollegeEmployeeUP> getAllEmployee(){
        List<CollegeEmployeeUP> collegeEmployeeUPList = new ArrayList<CollegeEmployeeUP>(10);
        for (int i = 0; i < 10; i++) {
            CollegeEmployeeUP temp = new CollegeEmployeeUP();
            temp.setId("学院员工  " + i);
            collegeEmployeeUPList.add(temp);
        }
        return collegeEmployeeUPList;
    }
    public void printCollegeEmployee(){
        List<CollegeEmployeeUP> allEmployee1 = this.getAllEmployee();
        System.out.println("-----------学校学院员工如下----------");
        for(CollegeEmployeeUP collegeEmployee : allEmployee1){
            System.out.println(collegeEmployee.getId());
        }
    }
}

// 学校管理类
class SchoolManagerUP{
    public List<SchoolEmployeeUP> getAllEmployee(){
        List<SchoolEmployeeUP> schoolEmployeeList = new ArrayList<SchoolEmployeeUP>(10);
        for (int i = 0; i < 10; i++) {
            SchoolEmployeeUP temp = new SchoolEmployeeUP();
            temp.setId("学校员工  " + i);
            schoolEmployeeList.add(temp);
        }
        return schoolEmployeeList;
    }
    public void printAllEmployee(CollegeManagerUP collegeManager){

        collegeManager.printCollegeEmployee();
        List<SchoolEmployeeUP> allEmployee = this.getAllEmployee();
        System.out.println("-----------学校员工如下----------");
        for(SchoolEmployeeUP schoolEmployee : allEmployee){
            System.out.println(schoolEmployee.getId());
        }

    }
}